package com.wzcl.app.dao.repository;

import com.wzcl.app.dao.model.CatalogEvaluateScore;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.beans.Transient;

public interface CatalogEvaluateScoreRepository extends JpaRepository<CatalogEvaluateScore, Integer>, JpaSpecificationExecutor {
    //通过章节id查询章节记录
    @Query(value = "select ces from CatalogEvaluateScore ces where ces.courseCatalog.id = ?1 and ces.appUser.id = ?2")
    CatalogEvaluateScore findEvaluateByCatalogId(Integer catalogId, Integer userId);

    @Transient
    @Modifying
    @Query(value = "delete from CatalogEvaluateScore ces where ces.courseCatalog.id = ?1 and ces.appUser.phone = ?2")
    void deleteByCatalogId(Integer catalogId, String phone);

    @Transactional
    @Modifying
    @Query(value = "delete from CatalogEvaluateScore ces where ces.id = ?1")
    void deleteById(Long id);
}